#include "Headers.h"

using namespace CinePerfil;
using namespace msclr::interop;

System::Void Change_Password_Window::CPW_okButton_Click(System::Object^  sender, System::EventArgs^  e)
{
	String^ pass_actual = this->CPW_currentPasswordTextBox->Text;

	if (pass_actual->Equals(marshal_as<String^>(account->get_password())))
	{
		String^ pass_1 = this->CPW_newPasswordTextBox->Text;
		String^ pass_2 = this->CPW_confirmNewPasswordTextBox->Text;

		if(pass_1->Equals(pass_2))
		{
			if (pass_1->Length < 6)
			{
				CPW_errorLabel->Text = "Password must have at least 6 characters and/or digits!\n";
				clear_textboxes(false);
				
			}
			else
			{
				account->set_password(marshal_as<string>(pass_1));
				this->Owner->Show();
				this->Close();
			}
		}
		else
		{
			CPW_errorLabel->Text = "New Password Mismatched!";
			clear_textboxes(false);
		}
	}
	else
	{
		CPW_errorLabel->Text = "Current Password Mismatched!";
		clear_textboxes(true);
	}
}
System::Void Change_Password_Window::CPW_cancelButton_Click(System::Object^  sender, System::EventArgs^  e)
{
	this->Owner->Show();
	this->Close();
}
System::Void Change_Password_Window::clear_textboxes(Boolean all)
{
	if(all)
	{
		CPW_currentPasswordTextBox->Text = "";
	}
	CPW_newPasswordTextBox->Text = "";
	CPW_confirmNewPasswordTextBox->Text = "";
}